package org.gp.Interfaz;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;

import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.FlowLayout;
import java.sql.SQLException;

import javax.swing.SwingConstants;

import org.gp.tringes.GestorBD;
import org.gp.tringes.GestorIGDatosClub;
import org.gp.tringes.GestorIGInicio;


public class IGClub extends JDialog {

	private int idClub;
	
	private JPanel panel;
	private JLabel lblZonaPers;
	private JPanel panel_1;
	private JButton btnConsClasif;
	private JButton btnGestPerros;
	private JButton btnInscribEnCarrera;
	private JButton btnGestTrineos;
	private JPanel panel_2;
	private JButton btnDesconec;
	private JButton btnCarrerasPendientes;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					IGClub dialog = new IGClub(1);
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);
					dialog.setModal(true);
					dialog.setResizable(false);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public IGClub(int pIdClub) {
		
		idClub = pIdClub;
		GestorIGDatosClub.getGestorIGDatosClub().obtenerDatosClub(idClub);
		
		setBounds(100, 100, 450, 250);
		//ID-76
		setTitle(GestorIGInicio.getGestorIGInicio().getTexto(76));
		
		getContentPane().setLayout(new BorderLayout(0, 0));
		getContentPane().add(getPanel(), BorderLayout.NORTH);
		getContentPane().add(getPanel_1(), BorderLayout.CENTER);
		getContentPane().add(getPanel_2(), BorderLayout.SOUTH);
	}
	
	private JPanel getPanel(){
		if(panel == null){
			panel = new JPanel();
			panel.setLayout(new GridLayout(1, 2, 0, 0));
			panel.add(getLblZonaPers());
		}
		return panel;
	}
	private JLabel getLblZonaPers(){
		if(lblZonaPers == null){
			//ID-76
			lblZonaPers = new JLabel(GestorIGInicio.getGestorIGInicio().getTexto(76));
			lblZonaPers.setHorizontalAlignment(SwingConstants.CENTER);
			lblZonaPers.setFont(new Font("Bastion", Font.PLAIN, 30));
			lblZonaPers.setBounds(15, 15, 290, 45);
		}
		return lblZonaPers;
	}
	
	private JPanel getPanel_1(){
		if(panel_1 == null){
			panel_1 = new JPanel();
			panel_1.setLayout(new GridLayout(3, 2, 10, 10));
			panel_1.add(getBtnConsClasif());
			panel_1.add(getBtnGestPerros());
			panel_1.add(getBtnInscribEnCarrera());
			panel_1.add(getBtnGestTrineos());
			panel_1.add(getBtnCarrerasPendientes());
		}
		return panel_1;
	}
	private JButton getBtnConsClasif(){
		if(btnConsClasif == null){
			//ID-77
			btnConsClasif = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(77));
			btnConsClasif.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					setVisible(false);
					JDialog espera = new IGEspera();
					espera.setLocationRelativeTo(null);
					espera.setVisible(true);
					JDialog clasif = new IGClasif(1,0,0,idClub);
					clasif.setResizable(false);
					clasif.setModal(true);
					clasif.setLocationRelativeTo(null);
					espera.dispose();
					clasif.setVisible(true);
			        setVisible(true);
				}
			});
		}
		return btnConsClasif;
	}
	private JButton getBtnGestPerros(){
		if(btnGestPerros == null){
			//ID-78
			btnGestPerros = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(78));
			btnGestPerros.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					setVisible(false);
					JDialog espera = new IGEspera();
					espera.setLocationRelativeTo(null);
					espera.setVisible(true);
					JDialog gestPerros = new IGPerrosClub(idClub);
					gestPerros.setResizable(false);
					gestPerros.setModal(true);
					gestPerros.setLocationRelativeTo(null);
					espera.dispose();
					gestPerros.setVisible(true);
			        setVisible(true);
				}
			});
		}
		return btnGestPerros;
	}
	private JButton getBtnInscribEnCarrera(){
		if(btnInscribEnCarrera == null){
			//ID-79
			btnInscribEnCarrera = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(79));
			btnInscribEnCarrera.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					setVisible(false);
					JDialog espera = new IGEspera();
					espera.setLocationRelativeTo(null);
					espera.setVisible(true);
					JDialog inscCarr = new IGInscribirEnCarrera(idClub);
					inscCarr.setResizable(false);
					inscCarr.setModal(true);
					inscCarr.setLocationRelativeTo(null);
					espera.dispose();
					inscCarr.setVisible(true);
			        setVisible(true);
				}
			});
		}
		return btnInscribEnCarrera;
	}
	private JButton getBtnGestTrineos(){
		if(btnGestTrineos == null){
			//ID-80
			btnGestTrineos = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(80));
			btnGestTrineos.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					setVisible(false);
					JDialog espera = new IGEspera();
					espera.setLocationRelativeTo(null);
					espera.setVisible(true);
					JDialog gesTrineos = new IGGestionarTrineos(idClub);
					gesTrineos.setResizable(false);
					gesTrineos.setModal(true);
					gesTrineos.setLocationRelativeTo(null);
					espera.dispose();
					gesTrineos.setVisible(true);
			        setVisible(true);
				}
			});
		}
		return btnGestTrineos;
	}
	private JButton getBtnCarrerasPendientes() {
		if (btnCarrerasPendientes == null) {
			//ID-81
			btnCarrerasPendientes = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(81));
			btnCarrerasPendientes.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					setVisible(false);
					JDialog espera = new IGEspera();
					espera.setLocationRelativeTo(null);
					espera.setVisible(true);
					JDialog carrerasPend = new IGCarrerasPend(idClub);
					carrerasPend.setResizable(false);
					carrerasPend.setModal(true);
					carrerasPend.setLocationRelativeTo(null);
					espera.dispose();
					carrerasPend.setVisible(true);
			        setVisible(true);
				}
			});
		}
		return btnCarrerasPendientes;
	}
	
	private JPanel getPanel_2(){
		if(panel_2 == null){
			panel_2 = new JPanel();
			panel_2.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
			panel_2.add(getBtnDesconec());
		}
		return panel_2;
	}
	private JButton getBtnDesconec(){
		if(btnDesconec == null){
			//ID-14
			btnDesconec = new JButton(GestorIGInicio.getGestorIGInicio().getTexto(14));
			btnDesconec.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					//ID-15 y 4
					int opcion = JOptionPane.showConfirmDialog(null, GestorIGInicio.getGestorIGInicio().getTexto(15), GestorIGInicio.getGestorIGInicio().getTexto(4), JOptionPane.YES_NO_OPTION);
					if(opcion == 0){
						try {
							GestorBD.getInstance().CerrarConexion();
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						System.exit(0);
					}
				}
			});
		}
		return btnDesconec;
	}
	
}